using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using IGlobalist.Chat.Engine;


using IGlobalist.Cms.Common;
namespace IGlobalist.Cms.Chat
{
    public partial class UserLogin : ChatBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IGlobalist.Cms.Model.User currentUser=(IGlobalist.Cms.Model.User) Session[SessionVariable.User.CurrentUserLoggedOn];
                if (currentUser != null && Session[SessionVariable.Chat.CurrentUserName] == null)
                {
                    Session[SessionVariable.Chat.CurrentUserName] = string.IsNullOrEmpty(currentUser.Email)?currentUser.UserName:currentUser.Email;
                }
                if (Session[SessionVariable.Chat.CurrentUserName] != null)
                {
                    string roomID = hdnRoomID.Value;
                    Response.Redirect("Chat.aspx?rid=" + roomID, true);
                }
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string email = txtEmail.Text;
            string roomID = hdnRoomID.Value;
            Room room = ChatEngine.GetRoom(roomID);
            if (room == null || room.GetUser(GetUserID(email, room.ID)) == null)
            {
                Session[SessionVariable.Chat.CurrentUserName] = email;
                Response.Redirect("Chat.aspx?rid=" + roomID, true);
            }
            else
            {
                lblError.Text = "Email :" + email + "exist!";
                lblError.Visible = true;
            }

        }
    }
}
